/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ivanbiz.service;

import com.ivanbiz.dao.JurnalDAO;
import com.ivanbiz.dao.impl.JurnalDAOImpl;
import com.ivanbiz.model.Jurnal;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zul.Label;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;

/**
 *
 * @author IW20149X
 */
public class LaporanJurnalViewService extends SelectorComposer<Component> {

    JurnalDAO jurnalDAO;
    SimpleDateFormat dateFormat;
    NumberFormat numberFormat;
    @Wire
    Label label;
    @Wire
    Listbox listJurnal;

    @Override
    public void doAfterCompose(Component comp) throws Exception {
        super.doAfterCompose(comp);
        listJurnal.getItems().clear();
        jurnalDAO = new JurnalDAOImpl();
        dateFormat = new SimpleDateFormat("dd-MMMM-yyyy");
        numberFormat = NumberFormat.getNumberInstance();
        Date dari = (Date) Executions.getCurrent().getArg().get("dari");
        Date sampai = (Date) Executions.getCurrent().getArg().get("sampai");
        label.setValue("Dari tanggal " + dateFormat.format(dari) + " sampai tanggal " + dateFormat.format(sampai));
        List<Jurnal> loadJurnal = jurnalDAO.getData(Jurnal.class, dari, sampai);
        int no = 0;
        int x = 0;
        String kode = "";
        for (Jurnal jurnal : loadJurnal) {
            Listitem item = new Listitem();
            item.setValue(jurnal);
            if (!kode.equals(jurnal.getTransactionReference())) {
                no += 1;
                kode = jurnal.getTransactionReference();
                item.appendChild(new Listcell(String.valueOf(no)));
                item.appendChild(new Listcell(dateFormat.format(jurnal.getDateReference())));
                item.appendChild(new Listcell(kode));
                item.appendChild(new Listcell(jurnal.getAccountingReference()));
                item.appendChild(new Listcell(jurnal.getCurrency()));
            } else {
                item.appendChild(new Listcell(""));
                item.appendChild(new Listcell(""));
                item.appendChild(new Listcell(""));
                item.appendChild(new Listcell(""));
                item.appendChild(new Listcell(""));
            }
            item.appendChild(new Listcell(numberFormat.format(jurnal.getDebit())));
            item.appendChild(new Listcell(numberFormat.format(jurnal.getCredit())));
            item.appendChild(new Listcell(jurnal.getGLAccount()));
            listJurnal.appendChild(item);
            ++x;
        }
    }
}
